package com.qianyucc.blog.controller.comm;

import com.qianyucc.blog.model.dto.*;
import com.qianyucc.blog.model.vo.*;
import com.qianyucc.blog.service.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.validation.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author lijing
 * @date 2019-10-17 16:46
 * @description 留言信息api
 */
@RestController
@RequestMapping("comm/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("获取所有留言")
    @GetMapping("/")
    public List<MessageVO> getMessages() {
        List<MessageVO> messages = messageService.findAllMessages();
        return messages;
    }

    @ApiOperation("提交留言")
    @PostMapping("/")
    public ResultVO leaveAMessage(@RequestBody @Validated MessageDTO messageDTO) {
        messageService.insMessage(messageDTO);
        return ResultVO.ok("留言成功！");
    }
}
